﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace WTSQCB
{
    public partial class TrinhDoDaoTao : System.Web.UI.Page
    {
        private string chuoiketnoi = ConfigurationManager.ConnectionStrings["WebDiemTSQCBConnectionString"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ThemButton1_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection(chuoiketnoi);
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "TrinhDoThem";
                cmd.Parameters.AddWithValue("@matrinhdo", MaTrinhDoTextBox1.Text);
                cmd.Parameters.AddWithValue("@tentrinhdo", TenTrinhDoTextBox2.Text);
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                TrinhDoGridView1.DataBind();
                Response.Write("Thêm thành công");
            }
            catch
            {
                Response.Write("không thực hiện được");
            }
        }

        protected void SuaButton2_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection(chuoiketnoi);
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "TrinhDoSua";
                cmd.Parameters.AddWithValue("@matrinhdo", MaTrinhDoTextBox1.Text);
                cmd.Parameters.AddWithValue("@tentrinhdo", TenTrinhDoTextBox2.Text);
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                TrinhDoGridView1.DataBind();
                Response.Write("Sửa thành công");
            }
            catch
            {
                Response.Write("không thực hiện được");
            }
        }

        protected void XoaButton3_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection(chuoiketnoi);
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "TrinhDoXoa";
                //cmd.Parameters.AddWithValue("@matrinhdo", TrinhDoGridView1.SelectedRow.Cells[1].Text);
                cmd.Parameters.AddWithValue("@matrinhdo", MaTrinhDoTextBox1.Text);
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                TrinhDoGridView1.DataBind();
                Response.Write("Xóa thành công");
            }
            catch
            {
                Response.Write("không thực hiện được");
            }
        }
        KetNoiDuLieu kn = new KetNoiDuLieu();
        protected void TrinhDoGridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow dong = TrinhDoGridView1.SelectedRow;
            //MaTrinhDoTextBox1.Text = Convert.ToString(kn.LoadData("TrinhDoLoad").Rows[TrinhDoGridView1.SelectedIndex].ItemArray[0]);
            //TenTrinhDoTextBox2.Text = Convert.ToString(kn.LoadData("TrinhDoLoad").Rows[TrinhDoGridView1.SelectedIndex].ItemArray[1]);
            MaTrinhDoTextBox1.Text = HttpUtility.HtmlDecode(dong.Cells[1].Text);
            TenTrinhDoTextBox2.Text = HttpUtility.HtmlDecode(dong.Cells[2].Text);
        }
    }
}